import celery
import time


broker = 'amqp://admin:123456@10.4.7.20:5672'
backend = 'redis://10.4.7.10:6379/1'

cel = celery.Celery('app', broker=broker, backend=backend)

cel.conf.update(broker_connection_timeout=4.0, broker_connection_max_retries=3, broker_connection_retry_on_startup=True)

@cel.task
def send_email(name):
    task_id = send_email.request.id
    print(f"Task ID: {task_id}")

    print("向%s发送邮件..." % name)
    time.sleep(5)
    print("向%s发送邮件完成" % name)
    return "ok"


@cel.task
def send_msg(name):
    task_id = send_msg.request.id
    print(f"Task ID: {task_id}")

    print("向%s发送短信..." % name)
    time.sleep(5)
    print("向%s发送短信完成" % name)
    return "ok"